-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for detecting project ID. Fixes #97 #98
Conversation
What do you think about putting the project ID as a property on the authClient / a getter? Since users of the library are likely caching the authClient, it should be easier for them to just grab the projectId off of that object as opposed to additionally caching the projectId returned when they create the client. |
They are related but still separate concerns. One is a set of credentials (a json key file), the other an identifier for a project. The // Get just the project ID
auth.getDefaultProjectId(function (err, projectId) {
// The project ID has now been cached
console.log(auth._cachedProjectId === projectId); // true
}); // Retrieve credentials and the project id
auth.getApplicationDefault(function (err, credentials, projectId) {
// Both are cached
console.log(auth._cachedCredential === credentials); // true
console.log(auth._cachedProjectId === projectId); // true
}); This is how python is implementing it: import google.auth
credentials, project_id = google.auth.default() |
I think the functionality of auto-detection of a project ID is quite helpful, and I think users will appreciate it, too. My thought is we should make it as easy as possible for them to get by putting it on the authClient instance so they don't have to "catch it before it's gone" (in the callback of the auth client fetcher). But either way, |
It won't be gone, it's cached on the
👍, though personally I would have function addScope(err, authClient, projectId) {
if (err) {
callback(err);
return;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
// ...
}
self.authClient = authClient;
self.projectId = projectId;
callback(null, authClient, projectId);
} Then |
I guess all I'm really saying is it shouldn't be "private". In JS, the leading
Yep, that's exactly how I would do it :) |
So perhaps we should also add synchronous getters to google-auth-library-nodejs for the credentials and projectId |
Can we also read the project_id from a service account keyfile? |
Is that in the case I don't have |
Yeah, newer Service Account key files have a
|
Does this library accept a key file path provided directly as a string, though? This is how I do it in google-auto-auth, but I'm not sure if I'm doing it in a way that this library intended to support. |
Passing
|
@jmdobry what's the process for getting this shipped? |
I'm not sure. Wishing I had write access. |
Fixes #97
project_id
field in GOOGLE_APPLICATION_CREDENTIALS key filecore/project
settingBefore
After